package com.yc.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/controller")
public class ParamDO {

    //{ } 匹配路径并捕获为变量
    @RequestMapping("/pv/{p1}")
    @ResponseBody
    public String pathVariable(@PathVariable String p1) {
        return p1;
    }

    @RequestMapping("/headers")
    @ResponseBody
    //将请求标头绑定到控制器中的方法参数
    public String headers(@RequestHeader String Host, @RequestHeader("Accept") String accept) {
        return Host + "::" + accept;
    }

    @RequestMapping("/cookie")
    @ResponseBody
    //用于将HTTP cookie的值绑定到控制器中的方法参数
    public String cookie(@CookieValue(required = false) String name) {
        return name;
    }

    @RequestMapping(path = "/save",produces = "text/html;charset=utf-8")
    @ResponseBody
    //用于注入指定的会话属性值
    public String saveSession(
            String myName, String value, HttpSession session){
        session.setAttribute(myName,value);
        return "保存数据到会话中了";
    }
}